import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../resources.dart';
import '../system_ui_style.dart';

class ContentPage extends ConsumerStatefulWidget {
  const ContentPage({super.key});

  @override
  ConsumerState<ConsumerStatefulWidget> createState() => _ContentPageState();
}

class _ContentPageState extends ConsumerState<ContentPage> {
  late final _pageController = PageController(initialPage: 0);

  @override
  void initState() {
    super.initState();
    // SystemChannels.platform.
  }

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiStyle.uiOverlay(Brightness.light),
        child: Scaffold(
            backgroundColor: Resources.white,
            body: Stack(children: [
              PageView.builder(
                  itemCount: 2,
                  onPageChanged: (int index) {},
                  controller: _pageController,
                  itemBuilder: (BuildContext context, int index) {
                    return index == 0 ? _page1Widget() : _page2Widget();
                  }),
              Center(
                  child: Column(mainAxisSize: MainAxisSize.min, children: [
                Row(mainAxisSize: MainAxisSize.min, children: [
                  TextButton(
                      onPressed: () async {
                        SystemUiStyle.uiMode(SystemUiMode.edgeToEdge);
                      },
                      style: TextButton.styleFrom(backgroundColor: Colors.amber, minimumSize: const Size(120, 40)),
                      child: const Text('edgeToEdge', style: TextStyle(color: Colors.white))),
                  const SizedBox(width: 20),
                  TextButton(
                      onPressed: () async {
                        SystemUiStyle.uiMode(SystemUiMode.immersive);
                      },
                      style: TextButton.styleFrom(backgroundColor: Colors.amber, minimumSize: const Size(120, 40)),
                      child: const Text('immersive', style: TextStyle(color: Colors.white))),
                ]),
                const SizedBox(height: 20),
                Row(mainAxisSize: MainAxisSize.min, children: [
                  TextButton(
                      onPressed: () async {
                        SystemUiStyle.uiMode(SystemUiMode.immersiveSticky);
                      },
                      style: TextButton.styleFrom(backgroundColor: Colors.amber, minimumSize: const Size(120, 40)),
                      child: const Text('immersiveSticky', style: TextStyle(color: Colors.white))),
                  const SizedBox(width: 20),
                  TextButton(
                      onPressed: () async {
                        SystemUiStyle.uiMode(SystemUiMode.leanBack);
                      },
                      style: TextButton.styleFrom(backgroundColor: Colors.amber, minimumSize: const Size(120, 40)),
                      child: const Text('leanBack', style: TextStyle(color: Colors.white))),
                ]),
                    const SizedBox(height: 20),
                    Row(mainAxisSize: MainAxisSize.min, children: [
                      TextButton(
                          onPressed: () async {
                            SystemUiStyle.uiMode(SystemUiMode.manual);
                          },
                          style: TextButton.styleFrom(backgroundColor: Colors.amber, minimumSize: const Size(120, 40)),
                          child: const Text('manual', style: TextStyle(color: Colors.white))),
                      const SizedBox(width: 20),
                      // TextButton(
                      //     onPressed: () async {
                      //       SystemUiStyle.uiMode(SystemUiMode.leanBack);
                      //     },
                      //     style: TextButton.styleFrom(backgroundColor: Colors.amber, minimumSize: const Size(120, 40)),
                      //     child: const Text('leanBack', style: TextStyle(color: Colors.white))),
                    ]),
              ]))
            ])));
  }

  Widget _page1Widget() {
    return Container(
        height: double.infinity,
        color: Resources.f8f9fc,
        child: Column(children: [
          AspectRatio(
              aspectRatio: 1125 / 637,
              child: CachedNetworkImage(imageUrl: "https://upftimage.dailyworkout.cn/image/86de2b500b539a4f579b79eeb83db905.jpg"))
        ]));
  }

  Widget _page2Widget() {
    return Container(
        height: double.infinity,
        color: Resources.f8f9fc,
        child: Stack(children: [
          AspectRatio(
              aspectRatio: 1125 / 637,
              child: CachedNetworkImage(imageUrl: "https://upftimage.dailyworkout.cn/image/86de2b500b539a4f579b79eeb83db905.jpg")),
          SafeArea(child: SizedBox(height: 48, child: AppBar())),
        ]));
  }
}
